package interfaces.console.commands;

import settings.ConfigFile;
import interfaces.console.Console;
import interfaces.console.commands.descriptors.OptionDescriptor;
import fileHandling.ProfileHandler;

public class SettingsCommand extends ArgumentCommand {
	
	private ConfigFile settings;
	private OptionDescriptor descriptor;
	
	public SettingsCommand(String commandName, ConfigFile settings) {
		super(commandName);
		this.settings = settings;
		
		descriptor = new OptionDescriptor(commandName, settings.getFileName());
	}
	
	@Override
	public String getCurrentValue() { return settings.getValueOf(commandName); }
	
	@Override
	public boolean execute(Console console, String[] args) {
		if(args.length != 2) return false;
		String argument = args[1];
		String error = descriptor.checkArgument(argument);
		if(error != null) {
			console.addToHistory(error, null);
			return false;
		}
		settings.addOption(commandName, argument);
		ProfileHandler.changeSettings(settings);
		return true;
	}
}